package com.zmsoft.boxy.sfg.service;

import org.cnsoft.framework.beans.common.RESTResultBean;
import org.cnsoft.framework.utils.EmptyHelper;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import com.zmsoft.boxy.sfg.player.BoxySFGPlayer;
import com.zmsoft.persistent.sfg.Sfg661010PlayerFarm.Sfg661010PlayerFarmDBO;
import com.zmsoft.persistent.sfg.Sfg661021PlayerLand.Sfg661021PlayerLandDBO;
import com.zmsoft.persistent.sfg.Sfg661030PlayerWarehouse.Sfg661030PlayerWarehouseDBO;
import com.zmsoft.persistent.sfg.Sfg661040PlayerPocket.Sfg661040PlayerPocketDBO;
import com.zmsoft.persistent.sfg.Sfg662010GameLand.Sfg662010GameLandDBO;
import com.zmsoft.persistent.sfg.Sfg662040GameCrops.Sfg662040GameCropsDBO;
import com.zmsoft.persistent.sfg.Sfg662041GameCropsGrow.Sfg662041GameCropsGrowDBO;
import com.zmsoft.persistent.sfg.Sfg662050GameShop.Sfg662050GameShopDBO;
import com.zmsoft.persistent.sfg.Sfg662060GameInteract.Sfg662060GameInteractDBO;

/**
 * 超管登录
 * 
 * @author ZmSoft
 * @version 0.1.0 2018/3/1
 * @since 0.1.0 2018/3/1
 * @see ApiManagerLoginController
 */
@Service("SFGGameActionService") // 替换系统登录接口
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
//@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class SFGGameActionService extends MySFGGameServiceSupport {

	/**
	 * 加载商店信息
	 */
	public RESTResultBean<BoxySFGPlayer> loadShop(BoxySFGPlayer player) throws Exception {
		RESTResultBean<BoxySFGPlayer> result = new RESTResultBean<BoxySFGPlayer>();
		result.setData(sfgGameInfoCacheService.loadGameShop(ONE));
		return result;
	}

	/**
	 * 商店购买信息
	 */
	public RESTResultBean<BoxySFGPlayer> doShopBuy(BoxySFGPlayer player) throws Exception {
		RESTResultBean<BoxySFGPlayer> result = new RESTResultBean<BoxySFGPlayer>();

		// 获得物品信息
		Sfg662050GameShopDBO gameShopCrop = sfgGameInfoCacheService.loadGameShopData(SFG_GAME_FARM_TYPE, player.getPlayerPropId());
		// 用户农场信息
		Sfg661010PlayerFarmDBO playerFarm = sfgPlayerInfoCacheService.loadPlayerFarm(player);
		// 用户口袋数据
		Sfg661040PlayerPocketDBO playerPocketProp = sfgPlayerInfoCacheService.loadPlayerPocketProp(player);

		if (gameShopCrop.getWaresPrice() > playerFarm.getCurMoney()) {// 金钱不足
			result.setCode(1);
			result.setMsg(FAIL_MESSAGE_Money);
			return result;
		}
		if (EmptyHelper.isEmpty(playerPocketProp)) {
			// 保存物品
			playerPocketProp = new Sfg661040PlayerPocketDBO();
			playerPocketProp.setPlayerId(player.getUserId());
			playerPocketProp.setPropId(gameShopCrop.getId());
			playerPocketProp.setPropName(gameShopCrop.getWaresName());
			playerPocketProp.setPropType(gameShopCrop.getWaresTypeCode());
			playerPocketProp.prepareNumeric();
		}
		// 开始购买物品
		{
			// 修正物品数量
			playerPocketProp.setPropNum(playerPocketProp.getPropNum() + gameShopCrop.getWaresNum());
			// 修正剩余金币
			playerFarm.setCurMoney(playerFarm.getCurMoney() - gameShopCrop.getWaresPrice());
			// 用户数据集中保存
			sfgPlayerInfoCacheService.savePlayer(player, playerFarm, null, null, playerPocketProp);
			// 设定返回
			result.setData(playerFarm);
		}

		// 设置返回信息
		result.setMsg(ACTION_OK_MESSAGE);
		return result;
	}

	/**
	 * 作物种植信息
	 */
	public RESTResultBean<BoxySFGPlayer> doLandPlant(BoxySFGPlayer player) throws Exception {
		RESTResultBean<BoxySFGPlayer> result = new RESTResultBean<BoxySFGPlayer>();
		// 用户农场信息
		Sfg661010PlayerFarmDBO playerFarm = sfgPlayerInfoCacheService.loadPlayerFarm(player);
		// 获得用户土地信息
		Sfg661021PlayerLandDBO playerLand = sfgPlayerInfoCacheService.loadPlayerLand(player);
		// 用户口袋数据
		Sfg661040PlayerPocketDBO playerPocketProp = sfgPlayerInfoCacheService.loadPlayerPocketProp(player);
		// 1未开垦2未种植3成长中5成熟待收割9收割后未翻地)
		if (EmptyHelper.isEmpty(playerFarm) || EmptyHelper.isEmpty(playerLand) || EmptyHelper.isEmpty(playerPocketProp)) {
			result.setCode(1);
			result.setMsg(FAIL_MESSAGE_BUG);
			return result;
		}
		// 合理化检查
		if (TWO.equals(playerLand.getLandState()) == false) {
			result.setCode(1);
			result.setMsg(FAIL_ACTION_sow);
			return result;
		}
		// 获得物品信息
		Sfg662040GameCropsDBO gameCrop = sfgGameInfoCacheService.loadGameCropsData(SFG_GAME_FARM_TYPE, playerPocketProp.getPropId());
		if (EmptyHelper.isEmpty(gameCrop)) {
			result.setCode(1);
			result.setMsg(FAIL_MESSAGE_BUG);
			return result;
		}
		// 检查需要金钱、等级、道具
		{
			if (gameCrop.getNeedMoney() > playerFarm.getCurMoney()) {// 金钱不足
				result.setCode(1);
				result.setMsg(FAIL_MESSAGE_Money);
				return result;
			}
			if (gameCrop.getNeedFarmLevel() > playerFarm.getFarmLevel()) {// 农场等级不足
				result.setCode(1);
				result.setMsg(FAIL_MESSAGE_FarmLevel);
				return result;
			}
			if (gameCrop.getNeedExp() > playerFarm.getTotalExp()) {// 消耗经验
				result.setCode(1);
				result.setMsg(FAIL_MESSAGE_Exp);
				return result;
			}
			{// 时间秒
			}
		}
		// 扣除需要金钱和经验、道具
		{
			playerFarm.setCurMoney(playerFarm.getCurMoney() - gameCrop.getNeedMoney());
			SFGGameThrusterServiceHelper.preparePlayerFarmTodayExp(sfgGameInfoCacheService, sfgPlayerInfoCacheService, playerFarm, gameCrop.getNeedExp() * (-1L));
			playerLand.setLandState(THREE);
		}
		// 扣除口袋物品
		if (playerPocketProp.getPropNum() > 0) {
			playerPocketProp.setPropNum(playerPocketProp.getPropNum() - 1);
		} else {
			result.setCode(1);
			result.setMsg(FAIL_MESSAGE_Pocket);
			return result;
		}
		// 整理植物基本数据到土地下面
		{
			// 作物ID
			playerLand.setCropsId(gameCrop.getId());
			// 作物名称
			playerLand.setCropsName(gameCrop.getCropsName());
			// 作物等级
			playerLand.setCropsLevel(gameCrop.getCropsLevel());
			// 成熟需要时间秒
			playerLand.setCropsNeedTime(gameCrop.getNeedTime());
			// 种植时间-秒
			playerLand.setPlantTime(System.currentTimeMillis());// 开始时间
			// 季数
			playerLand.setSeasonsNum(1L);
		}
		// 整理植物阶段数据到土地下面
		Sfg662041GameCropsGrowDBO gameCropsGrowDBO = sfgGameInfoCacheService.loadGameCropsGrowData(SFG_GAME_FARM_TYPE, playerPocketProp.getPropId(), ONE);
		if (EmptyHelper.isEmpty(gameCropsGrowDBO)) {
			result.setCode(1);
			result.setMsg(FAIL_MESSAGE_BUG);
			return result;
		}
		{
			// 当前阶段ID
			playerLand.setStageId(gameCropsGrowDBO.getId());
			// 当前阶段名称
			playerLand.setStageName(gameCropsGrowDBO.getStageName());
			// 土地图片
			playerLand.setLandPicUrl(gameCropsGrowDBO.getStagePicUrl());
			// 当前阶段需要时间(秒) need_time
			playerLand.setNeedTime(gameCropsGrowDBO.getNeedTime());
			playerLand.setCropsNeedTime1(gameCropsGrowDBO.getNeedTime());

			// 事件触发
			SFGGameThrusterServiceHelper.preparePlayerLandCropsState(sfgGameInfoCacheService, sfgPlayerInfoCacheService, playerLand, gameCrop, gameCropsGrowDBO);

			// 动作增加经验
			SFGGameThrusterServiceHelper.preparePlayerFarmTodayExp(sfgGameInfoCacheService, sfgPlayerInfoCacheService, playerFarm, gameCropsGrowDBO.getCropsExp());
		}

		// 用户数据集中保存
		sfgPlayerInfoCacheService.savePlayer(player, playerFarm, playerLand, null, playerPocketProp);

		result.setMsg(ACTION_OK_MESSAGE);
		result.setData(playerLand);// 数据刷新展示

		// 补全各个阶段时间
		prepareLandCropsGrow(player, playerFarm, playerLand);

		return result;
	}

	// 补全各个阶段时间
	@Async("threadPoolTaskExecutor")
	public void prepareLandCropsGrow(BoxySFGPlayer player, Sfg661010PlayerFarmDBO farm, Sfg661021PlayerLandDBO land) throws Exception {
		// 1土地种子
		Sfg662041GameCropsGrowDBO gameCropsGrowDBO;
		// 2幼苗发芽
		gameCropsGrowDBO = sfgGameInfoCacheService.loadGameCropsGrowData(SFG_GAME_FARM_TYPE, land.getCropsId(), TWO);
		if (EmptyHelper.isNotEmpty(gameCropsGrowDBO)) {
			// 当前阶段需要时间(秒) need_time
			land.setCropsNeedTime2(gameCropsGrowDBO.getNeedTime());
		}
		// 3茁壮成长
		gameCropsGrowDBO = sfgGameInfoCacheService.loadGameCropsGrowData(SFG_GAME_FARM_TYPE, land.getCropsId(), THREE);
		if (EmptyHelper.isNotEmpty(gameCropsGrowDBO)) {
			// 当前阶段需要时间(秒) need_time
			land.setCropsNeedTime3(gameCropsGrowDBO.getNeedTime());
		}
		// 4长大开花
		gameCropsGrowDBO = sfgGameInfoCacheService.loadGameCropsGrowData(SFG_GAME_FARM_TYPE, land.getCropsId(), FOUR);
		if (EmptyHelper.isNotEmpty(gameCropsGrowDBO)) {
			// 当前阶段需要时间(秒) need_time
			land.setCropsNeedTime4(gameCropsGrowDBO.getNeedTime());
		}
		// 5成熟结果
		gameCropsGrowDBO = sfgGameInfoCacheService.loadGameCropsGrowData(SFG_GAME_FARM_TYPE, land.getCropsId(), FIVE);
		if (EmptyHelper.isNotEmpty(gameCropsGrowDBO)) {
			// 当前阶段需要时间(秒) need_time
			land.setCropsNeedTime5(gameCropsGrowDBO.getNeedTime());
		}
		// 6果实收割

		// 补全土地
		sfgPlayerInfoCacheService.preparePlayerFarmLand(farm);

		// 保存数据
		sfgPlayerInfoCacheService.savePlayerFarm(farm);
		sfgPlayerInfoCacheService.savePlayerLand(player, land);
	}

	/**
	 * 土地开垦信息(从无到有)[下一步种植]
	 */
	public RESTResultBean<BoxySFGPlayer> doLandReclamation(BoxySFGPlayer player) throws Exception {
		RESTResultBean<BoxySFGPlayer> result = new RESTResultBean<BoxySFGPlayer>();
		// 获得用户土地信息
		Sfg661021PlayerLandDBO playerLand = sfgPlayerInfoCacheService.loadPlayerLand(player);
		// 土地卡、经验值、好友
		// 1未开垦2未种植3成长中5成熟待收割9收割后未翻地)
		if (ONE.equals(playerLand.getLandState()) == false) {
			result.setCode(1);
			result.setMsg(FAIL_ACTION_bring);
			return result;
		}
		// 用户农场信息
		Sfg661010PlayerFarmDBO playerFarm = sfgPlayerInfoCacheService.loadPlayerFarm(player);
		// 获得土地升级配置
		Long nextLand = playerFarm.getLandNumUse() + 1;
		Sfg662010GameLandDBO gameLand = sfgGameInfoCacheService.loadGameLandData(SFG_GAME_FARM_TYPE, nextLand);
		// 检查需要金钱、等级、道具
		{
			if (gameLand.getNeedMoney() > playerFarm.getCurMoney()) {// 金钱不足
				result.setCode(1);
				result.setMsg(FAIL_MESSAGE_Money);
				return result;
			}
			if (gameLand.getNeedFarmLevel() > playerFarm.getFarmLevel()) {// 农场等级不足
				result.setCode(1);
				result.setMsg(FAIL_MESSAGE_FarmLevel);
				return result;
			}
		}
		// 扣除需要金钱和经验、道具
		{
			playerFarm.setCurMoney(playerFarm.getCurMoney() - gameLand.getNeedMoney());
			playerLand.setLandState(TWO);// 更新土地状态
			// 动作增加经验, 农场升级信息
			// TODO 等待转到配置
			SFGGameThrusterServiceHelper.preparePlayerFarmTodayExp(sfgGameInfoCacheService, sfgPlayerInfoCacheService, playerFarm, 5);
		}
		// 用户数据集中保存
		sfgPlayerInfoCacheService.savePlayer(player, playerFarm, playerLand, null, null);
		// 设置返回信息
		result.setMsg(ACTION_OK_MESSAGE);
		result.setData(playerLand);// 数据刷新展示
		return result;
	}

	//////////////////////////////////////////////////////////////////////////////////////////
	/**
	 * 浇水
	 */
	public RESTResultBean<BoxySFGPlayer> doLandPlantWatering(BoxySFGPlayer player) throws Exception {
		RESTResultBean<BoxySFGPlayer> result = new RESTResultBean<BoxySFGPlayer>();
		// 用户农场信息
		Sfg661010PlayerFarmDBO playerFarm = sfgPlayerInfoCacheService.loadPlayerFarm(player);
		// 获得用户土地信息
		Sfg661021PlayerLandDBO playerLand = sfgPlayerInfoCacheService.loadPlayerLand(player);// 获得物品信息
		// 获得物品信息
		Sfg662040GameCropsDBO gameCrop = sfgGameInfoCacheService.loadGameCropsData(SFG_GAME_FARM_TYPE, playerLand.getCropsId());

		// 交互动作配置
		Sfg662060GameInteractDBO gameInteract = sfgGameInfoCacheService.loadGameInteractData(GAME_INTERACT, playerLand.getActionId());
		if (EmptyHelper.isNotEmpty(gameInteract) && Interact_Command_doLandPlantWatering.equals(gameInteract.getActionCommandApi())) {
			// 动作增加经验, 农场升级信息
			SFGGameThrusterServiceHelper.preparePlayerFarmTodayExp(sfgGameInfoCacheService, sfgPlayerInfoCacheService, playerFarm, gameInteract.getAwardExp());
		} 
		// 减少次数
		{
			// 剩余浇水数目
			long leftWatering = playerLand.getLeftWatering() - 1;
			if (leftWatering < 1) {
				leftWatering = 0;
				// 阶段互动ID
				playerLand.setActionId(BLANK);
				// 阶段互动名称
				playerLand.setActionName(BLANK);
				// 功能操作指令
				playerLand.setActionCommandPage(BLANK);
				// 服务操作指令
				playerLand.setActionCommandApi(BLANK);
			}
			// 设置剩余浇水数目
			playerLand.setLeftWatering(leftWatering);
			// 作物增产
			SFGGameThrusterServiceHelper.peducePlayerLandCrops(sfgGameInfoCacheService, sfgPlayerInfoCacheService, playerLand, gameCrop, 65);
		}

		// 设置返回信息
		result.setMsg(ACTION_OK_MESSAGE);
		// 用户数据集中保存
		sfgPlayerInfoCacheService.savePlayer(player, playerFarm, playerLand, null, null);
		return result;
	}

	/**
	 * 施肥
	 */
	public RESTResultBean<BoxySFGPlayer> doLandPlantFertilize(BoxySFGPlayer player) throws Exception {
		RESTResultBean<BoxySFGPlayer> result = new RESTResultBean<BoxySFGPlayer>();
		// 用户农场信息
		Sfg661010PlayerFarmDBO playerFarm = sfgPlayerInfoCacheService.loadPlayerFarm(player);
		// 获得用户土地信息
		Sfg661021PlayerLandDBO playerLand = sfgPlayerInfoCacheService.loadPlayerLand(player);// 获得物品信息
		// 获得物品信息
		Sfg662040GameCropsDBO gameCrop = sfgGameInfoCacheService.loadGameCropsData(SFG_GAME_FARM_TYPE, playerLand.getCropsId());

		// 交互动作配置
		Sfg662060GameInteractDBO gameInteract = sfgGameInfoCacheService.loadGameInteractData(GAME_INTERACT, playerLand.getActionId());
		if (EmptyHelper.isNotEmpty(gameInteract) && Interact_Command_doLandPlantFertilize.equals(gameInteract.getActionCommandApi())) {
			// 动作增加经验, 农场升级信息
			SFGGameThrusterServiceHelper.preparePlayerFarmTodayExp(sfgGameInfoCacheService, sfgPlayerInfoCacheService, playerFarm, gameInteract.getAwardExp());
		} 
		// 减少次数
		{
			// 剩余施肥数目
			long leftFertilize = playerLand.getLeftFertilize() - 1;
			if (leftFertilize < 1) {
				leftFertilize = 0;
				// 阶段互动ID
				playerLand.setActionId(BLANK);
				// 阶段互动名称
				playerLand.setActionName(BLANK);
				// 功能操作指令
				playerLand.setActionCommandPage(BLANK);
				// 服务操作指令
				playerLand.setActionCommandApi(BLANK);
			}
			// 设置剩余施肥数目
			playerLand.setLeftFertilize(leftFertilize);
			// 作物增产
			SFGGameThrusterServiceHelper.peducePlayerLandCrops(sfgGameInfoCacheService, sfgPlayerInfoCacheService, playerLand, gameCrop, 65);

		}

		// 设置返回信息
		result.setMsg(ACTION_OK_MESSAGE);
		// 用户数据集中保存
		sfgPlayerInfoCacheService.savePlayer(player, playerFarm, playerLand, null, null);
		return result;
	}

	/**
	 * 除草
	 */
	public RESTResultBean<BoxySFGPlayer> doLandPlantWeed(BoxySFGPlayer player) throws Exception {
		RESTResultBean<BoxySFGPlayer> result = new RESTResultBean<BoxySFGPlayer>();
		// 用户农场信息
		Sfg661010PlayerFarmDBO playerFarm = sfgPlayerInfoCacheService.loadPlayerFarm(player);
		// 获得用户土地信息
		Sfg661021PlayerLandDBO playerLand = sfgPlayerInfoCacheService.loadPlayerLand(player);// 获得物品信息
		// 获得物品信息
		Sfg662040GameCropsDBO gameCrop = sfgGameInfoCacheService.loadGameCropsData(SFG_GAME_FARM_TYPE, playerLand.getCropsId());

		// 交互动作配置
		Sfg662060GameInteractDBO gameInteract = sfgGameInfoCacheService.loadGameInteractData(GAME_INTERACT, playerLand.getActionId());
		if (EmptyHelper.isNotEmpty(gameInteract) && Interact_Command_doLandPlantWeed.equals(gameInteract.getActionCommandApi())) {
			// 动作增加经验, 农场升级信息
			SFGGameThrusterServiceHelper.preparePlayerFarmTodayExp(sfgGameInfoCacheService, sfgPlayerInfoCacheService, playerFarm, gameInteract.getAwardExp());
		}
		// 减少次数 
		{
			// 剩余除草数目
			long leftWeeding = playerLand.getLeftWeeding() - 1;
			if (leftWeeding < 1) {
				leftWeeding = 0;
				// 阶段互动ID
				playerLand.setActionId(BLANK);
				// 阶段互动名称
				playerLand.setActionName(BLANK);
				// 功能操作指令
				playerLand.setActionCommandPage(BLANK);
				// 服务操作指令
				playerLand.setActionCommandApi(BLANK);
			}
			// 设置剩余除草数目
			playerLand.setLeftWeeding(leftWeeding);
			// 作物增产
			SFGGameThrusterServiceHelper.peducePlayerLandCrops(sfgGameInfoCacheService, sfgPlayerInfoCacheService, playerLand, gameCrop, 65);

		}

		// 设置返回信息
		result.setMsg(ACTION_OK_MESSAGE);
		// 用户数据集中保存
		sfgPlayerInfoCacheService.savePlayer(player, playerFarm, playerLand, null, null);
		return result;
	}

	/**
	 * 杀虫
	 */
	public RESTResultBean<BoxySFGPlayer> doLandPlantInsecticidal(BoxySFGPlayer player) throws Exception {
		RESTResultBean<BoxySFGPlayer> result = new RESTResultBean<BoxySFGPlayer>();
		// 用户农场信息
		Sfg661010PlayerFarmDBO playerFarm = sfgPlayerInfoCacheService.loadPlayerFarm(player);
		// 获得用户土地信息
		Sfg661021PlayerLandDBO playerLand = sfgPlayerInfoCacheService.loadPlayerLand(player);// 获得物品信息
		// 获得物品信息
		Sfg662040GameCropsDBO gameCrop = sfgGameInfoCacheService.loadGameCropsData(SFG_GAME_FARM_TYPE, playerLand.getCropsId());

		// 交互动作配置
		Sfg662060GameInteractDBO gameInteract = sfgGameInfoCacheService.loadGameInteractData(GAME_INTERACT, playerLand.getActionId());
		if (EmptyHelper.isNotEmpty(gameInteract) && Interact_Command_doLandPlantInsecticidal.equals(gameInteract.getActionCommandApi())) {
			// 动作增加经验, 农场升级信息
			SFGGameThrusterServiceHelper.preparePlayerFarmTodayExp(sfgGameInfoCacheService, sfgPlayerInfoCacheService, playerFarm, gameInteract.getAwardExp());
		} 
		// 减少次数
		{
			// 剩余杀虫数目
			long leftInsect = playerLand.getLeftInsect() - 1;
			if (leftInsect < 1) {
				leftInsect = 0;
				// 阶段互动ID
				playerLand.setActionId(BLANK);
				// 阶段互动名称
				playerLand.setActionName(BLANK);
				// 功能操作指令
				playerLand.setActionCommandPage(BLANK);
				// 服务操作指令
				playerLand.setActionCommandApi(BLANK);
			}
			// 设置剩余浇水数目
			playerLand.setLeftInsect(leftInsect);
			// 作物增产
			SFGGameThrusterServiceHelper.peducePlayerLandCrops(sfgGameInfoCacheService, sfgPlayerInfoCacheService, playerLand, gameCrop, 65);

		}

		// 设置返回信息
		result.setMsg(ACTION_OK_MESSAGE);
		// 用户数据集中保存
		sfgPlayerInfoCacheService.savePlayer(player, playerFarm, playerLand, null, null);
		return result;
	}

	/**
	 * 摘取果实
	 */
	public RESTResultBean<BoxySFGPlayer> doLandPlantPick(BoxySFGPlayer player) throws Exception {
		RESTResultBean<BoxySFGPlayer> result = new RESTResultBean<BoxySFGPlayer>();
		// 用户农场信息
		Sfg661010PlayerFarmDBO playerFarm = sfgPlayerInfoCacheService.loadPlayerFarm(player);
		// 获得用户土地信息
		Sfg661021PlayerLandDBO playerLand = sfgPlayerInfoCacheService.loadPlayerLand(player);
		// 判断作物状态
		if (SIX.equals(playerLand.getStageId()) == false) {
			// 非法操作
			result.setCode(1);
			result.setMsg(FAIL_MESSAGE_BUG);
			return result;
		}

		// 补全作物ID
		player.setPlayerPropId(playerLand.getCropsId());
		// 用户仓库数据
		Sfg661030PlayerWarehouseDBO playerWarehouseProp = sfgPlayerInfoCacheService.loadPlayerWarehouseProp(player);
		// 果实数目
		long fruit = playerLand.getFruitMax() - (playerLand.getFruitStealMax() - playerLand.getFruitStealLeft());
		// 保存仓库
		if (EmptyHelper.isEmpty(playerWarehouseProp)) {
			playerWarehouseProp = new Sfg661030PlayerWarehouseDBO();
			playerWarehouseProp.prepareNumeric();
			playerWarehouseProp.setPlayerId(player.getUserId());
			playerWarehouseProp.setPlayerName(player.getUserName());
			// 物品ID
			playerWarehouseProp.setPropId(playerLand.getCropsId());
			// 物品名称
			playerWarehouseProp.setPropName(playerLand.getCropsName());
			// 设置物品类别(1农作物2家畜3水产5产品9其他)
			playerWarehouseProp.setPropType(ONE);
			// 设置单一物品占用仓库容积大小
			playerWarehouseProp.setPropVolume(playerLand.getFruitVolume());
		}

		// 设置果实数目
		playerWarehouseProp.setPropNum(playerWarehouseProp.getPropNum() + fruit);

		// 动作增加经验, 农场升级信息
		SFGGameThrusterServiceHelper.preparePlayerFarmTodayExp(sfgGameInfoCacheService, sfgPlayerInfoCacheService, playerFarm, playerLand.getCropsExp());

		// 修正土地状态
		Long landSort = playerLand.getLandSort();
		{
			playerLand = new Sfg661021PlayerLandDBO();
			playerLand.setPlayerId(player.getUserId());
			playerLand.setPlayerName(player.getUserName());
			playerLand.setLandState(NINE);// 1未开垦2未种植3成长中5成熟待收割9收割后未翻地
			playerLand.setLandSort(landSort);
		}

		// 设置返回信息
		result.setMsg(ACTION_OK_MESSAGE);
		// 用户数据集中保存
		sfgPlayerInfoCacheService.savePlayer(player, playerFarm, playerLand, playerWarehouseProp, null);
		return result;
	}

	/**
	 * 翻地
	 */
	public RESTResultBean<BoxySFGPlayer> doLandTurn(BoxySFGPlayer player) throws Exception {
		RESTResultBean<BoxySFGPlayer> result = new RESTResultBean<BoxySFGPlayer>();
		// 用户农场信息
		Sfg661010PlayerFarmDBO playerFarm = sfgPlayerInfoCacheService.loadPlayerFarm(player);
		// 获得用户土地信息
		Sfg661021PlayerLandDBO playerLand = sfgPlayerInfoCacheService.loadPlayerLand(player);
		// 交互动作配置
		Sfg662060GameInteractDBO gameInteract = sfgGameInfoCacheService.loadGameInteractData(GAME_INTERACT, playerLand.getActionId());
		if (EmptyHelper.isNotEmpty(gameInteract) && Interact_Command_doLandTurn.equals(gameInteract.getActionCommandApi())) {
			// 动作增加经验, 农场升级信息
			SFGGameThrusterServiceHelper.preparePlayerFarmTodayExp(sfgGameInfoCacheService, sfgPlayerInfoCacheService, playerFarm, playerLand.getCropsExp());
		}
		// 修正土地状态
		Long landSort = playerLand.getLandSort();
		{
			playerLand = new Sfg661021PlayerLandDBO();
			playerLand.setPlayerId(player.getUserId());
			playerLand.setPlayerName(player.getUserName());
			playerLand.setLandState(TWO);// 1未开垦2未种植3成长中5成熟待收割9收割后未翻地
			playerLand.setLandSort(landSort);
		}

		// 设置返回信息
		result.setMsg(ACTION_OK_MESSAGE);
		// 用户数据集中保存
		sfgPlayerInfoCacheService.savePlayer(player, playerFarm, playerLand, null, null);
		return result;
	}

}
